home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / wb / flynn / source / window.c < prev    next >
C/C++ Source or Header  |  1999-06-15  |  7KB  |  259 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #include <utility/tagitem.h>
  7. #include <intuition/intuition.h>
  8. #include <guigfx/guigfx.h>
  9. #include <exec/memory.h>
  10.  
  11. #include <clib/macros.h>
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/intuition.h>
  15. #include <proto/graphics.h>
  16. #include <proto/utility.h>
  17. #include <proto/guigfx.h>
  18. #include <proto/intuition.h>
  19. #include <proto/guigfx.h>
  20.  
  21. #include "defs.h"
  22. #include "global.h"
  23. #include "window.h"
  24.  
  25.  
  26. /*********************************************************************
  27. ----------------------------------------------------------------------
  28.  
  29.     ClearWindow(win)
  30.  
  31. ----------------------------------------------------------------------
  32. *********************************************************************/
  33.  
  34. void ClearWindow(struct mvwindow *win)
  35. {
  36.     UpdateWindowParameters(win);
  37.     SetABPenDrMd(win->window->RPort, win->backpen, win->backpen, JAM1);
  38.  
  39.     RectFill(win->window->RPort, 
  40.         win->innerleft + win->leftoffs, 
  41.         win->innertop + win->topoffs,
  42.         win->innerleft+win->innerwidth-win->rightoffs-1,
  43.         win->innertop+win->innerheight-win->bottomoffs-1);
  44. }
  45.  
  46.  
  47. /*********************************************************************
  48. ----------------------------------------------------------------------
  49.  
  50.     void UpdateWindowParameters(mvwindow)
  51.  
  52.     get current window parameters
  53.  
  54. ----------------------------------------------------------------------
  55. *********************************************************************/
  56.  
  57. void UpdateWindowParameters(struct mvwindow *win)
  58. {
  59.     win->winleft = win->window->LeftEdge;
  60.     win->wintop = win->window->TopEdge;
  61.     win->winwidth = win->window->Width;
  62.     win->winheight = win->window->Height;
  63.     win->innerleft = win->window->BorderLeft;
  64.     win->innertop = win->window->BorderTop;
  65.     win->innerwidth = win->winwidth - win->innerleft - win->window->BorderRight;
  66.     win->innerheight = win->winheight - win->innertop - win->window->BorderBottom;
  67. }
  68.  
  69.  
  70. /*********************************************************************
  71. ----------------------------------------------------------------------
  72.  
  73.     DeleteMVWindow (mvwindow)
  74.  
  75. ----------------------------------------------------------------------
  76. *********************************************************************/
  77.  
  78. void DeleteMVWindow (struct mvwindow *win)
  79. {
  80.     if (win)
  81.     {
  82.         if (win->window)
  83.         {
  84.             ReleasePen(win->screen->ViewPort.ColorMap, win->backpen);
  85.             CloseWindow(win->window);
  86.         }
  87.         
  88.         Free(win);
  89.     }
  90. }
  91.  
  92.  
  93. /*********************************************************************
  94. ----------------------------------------------------------------------
  95.  
  96.     mvwindow = CreateMVWindow (screen)
  97.  
  98. ----------------------------------------------------------------------
  99. *********************************************************************/
  100.  
  101. #define inserttag(x,t,d) {(x)->ti_Tag=(t);((x)++)->ti_Data=(ULONG)(d);}
  102.  
  103. struct mvwindow *CreateMVWindow (WORD x, WORD y, WORD width, WORD height)
  104. {
  105.     struct mvwindow *win = NULL;
  106.     struct Screen *screen;
  107.  
  108.     if (screen = LockPubScreen(NULL))
  109.     {
  110.  
  111.         if (win = Malloclear(sizeof(struct mvwindow)))
  112.         {
  113.             BOOL success = FALSE;
  114.             struct TagItem *taglist;
  115.     
  116.             win->backpen = -1;
  117.     
  118.             win->screen = screen;
  119.     
  120.     
  121.             if(taglist = AllocateTagItems(20))
  122.             {
  123.                 UWORD visibleWidth, visibleHeight, visibleMidX, visibleMidY;
  124.         //        UWORD visibleLeft, visibleTop;
  125.                 WORD winwidth, winheight, wintop, winleft;
  126.                 struct TagItem *tp = taglist;
  127.                 ULONG modeID;
  128.             
  129.                 visibleWidth = screen->Width;
  130.                 visibleHeight = screen->Height;
  131.             
  132.                 if ((modeID = GetVPModeID(&screen->ViewPort)) != INVALID_ID)
  133.                 {
  134.                     DisplayInfoHandle dih;
  135.             
  136.                     if(dih = FindDisplayInfo(modeID))
  137.                     {
  138.                         struct DimensionInfo di;    
  139.             
  140.                         if(GetDisplayInfoData(dih, (UBYTE*) &di, sizeof(di), DTAG_DIMS, modeID))
  141.                         {
  142.                             visibleWidth = di.TxtOScan.MaxX - di.TxtOScan.MinX;
  143.                             visibleHeight = di.TxtOScan.MaxY - di.TxtOScan.MinY;
  144.                         }
  145.                     }
  146.                 }
  147.             
  148.         //        visibleLeft = -screen->ViewPort.DxOffset;
  149.         //        visibleTop = -screen->ViewPort.DyOffset;
  150.     
  151.                 visibleMidX = visibleWidth/2 - screen->ViewPort.DxOffset;
  152.                 visibleMidY = visibleHeight/2 - screen->ViewPort.DyOffset;
  153.             
  154.         //        winwidth = MAX(visibleWidth * 3 / 7, DEFAULT_MINWIDTH);
  155.         //        winheight = MAX(visibleHeight * 3 / 7, DEFAULT_MINHEIGHT);
  156.     
  157.                 winwidth = width;
  158.                 winheight = height;
  159.     
  160.                 inserttag(tp, WA_Width, winwidth);
  161.                 inserttag(tp, WA_Height, winheight);
  162.  
  163.                 winleft = (x >= 0) ? x : visibleMidX - winwidth/2;
  164.                 wintop = (y >= 0) ? y : visibleMidY - winheight/2;
  165.  
  166.                 inserttag(tp, WA_Left, winleft);
  167.                 inserttag(tp, WA_Top, wintop);
  168.         
  169.         //        win->otherwinpos[0] = visibleLeft;
  170.         //        win->otherwinpos[1] = visibleTop;
  171.         //        win->otherwinpos[2] = visibleWidth;
  172.         //        win->otherwinpos[3] = visibleHeight;
  173.     
  174.         //        inserttag(tp, WA_Zoom, &win->otherwinpos);
  175.     
  176.                 inserttag(tp, WA_PubScreen, screen);
  177.             
  178.         //        inserttag(tp, WA_Title, DEFAULT_WINTITLE);
  179.             
  180.                 inserttag(tp, WA_NewLookMenus, TRUE);
  181.             
  182.             
  183.                 inserttag(tp, WA_Flags, 
  184.                             WFLG_RMBTRAP |
  185.                             WFLG_BORDERLESS |
  186.                             WFLG_SMART_REFRESH);
  187.     
  188.                 inserttag(tp, WA_IDCMP, 
  189.                             IDCMP_NEWSIZE |
  190.                             IDCMP_ACTIVEWINDOW |
  191.                             IDCMP_INACTIVEWINDOW |
  192.                             IDCMP_VANILLAKEY | IDCMP_RAWKEY | 
  193.                             IDCMP_MOUSEBUTTONS);
  194.             
  195.                 inserttag(tp, WA_MinWidth, DEFAULT_MINWIDTH);
  196.                 inserttag(tp, WA_MinHeight, DEFAULT_MINHEIGHT);
  197.                 inserttag(tp, WA_MaxWidth, DEFAULT_MAXWIDTH);
  198.                 inserttag(tp, WA_MaxHeight, DEFAULT_MAXHEIGHT);
  199.     
  200.                 inserttag(tp, TAG_DONE, 0);
  201.             
  202.                 if(win->window = OpenWindowTagList(NULL, taglist))
  203.                 {
  204.                     win->idcmpSignal = 1L << win->window->UserPort->mp_SigBit;
  205.     
  206.                     win->backpen = ObtainBestPen(win->screen->ViewPort.ColorMap,
  207.                         RED_RGB32(RGB_CLEARWINDOW),
  208.                         GREEN_RGB32(RGB_CLEARWINDOW),
  209.                         BLUE_RGB32(RGB_CLEARWINDOW),
  210.                         OBP_Precision, PRECISION_ICON, TAG_DONE);
  211.  
  212.                     memset(&win->sizegadget, 0, sizeof(struct Gadget));
  213.                     win->sizegadget.LeftEdge = win->window->Width-SIZESIZE;
  214.                     win->sizegadget.TopEdge = win->window->Height-SIZESIZE;
  215.                     win->sizegadget.Width = SIZESIZE;
  216.                     win->sizegadget.Height = SIZESIZE;
  217.                     win->sizegadget.Flags = GFLG_GADGHNONE;
  218.                     win->sizegadget.Activation = 0;
  219.                     win->sizegadget.GadgetType = GTYP_SIZING;
  220.                     AddGadget(win->window, &win->sizegadget, ~0);
  221.             
  222.                     memset(&win->draggadget, 0, sizeof(struct Gadget));
  223.                     win->draggadget.LeftEdge = 0;
  224.                     win->draggadget.TopEdge = 0;
  225.                     win->draggadget.Width = win->window->Width;
  226.                     win->draggadget.Height = win->window->Height;
  227.                     win->draggadget.Flags = GFLG_GADGHNONE;
  228.                     win->draggadget.Activation = 0;
  229.                     win->draggadget.GadgetType = GTYP_WDRAGGING;
  230.                     AddGadget(win->window, &win->draggadget, ~0);
  231.  
  232.     
  233.                     ClearWindow(win);
  234.                     success = TRUE;
  235.                 }
  236.             
  237.                 FreeTagItems(taglist);
  238.             }
  239.     
  240.             
  241.             if (!success)
  242.             {
  243.                 DeleteMVWindow(win);
  244.                 win = NULL;
  245.             }
  246.         }
  247.         
  248.         UnlockPubScreen(NULL, screen);
  249.     }
  250.  
  251.     return win;
  252. }
  253.  
  254. #undef inserttag
  255.  
  256.  
  257.  
  258.  
  259.